package ua.com.globallogic.javatraining.iryna_chorna.univercity.people;

import java.util.Arrays;

import ua.com.globallogic.javatraining.iryna_chorna.univercity.structure.Course;


/**
 * class Teacher models a university teacher. 
 * Teacher has an academic degree and teaches(delivers) one or more <code>Course</code>
 */
public class Teacher extends Person {
	protected final int MAX_COURSES_COUNT = 20; 
	private AcademicDegree academicDegree;
	private Course[] coursesDelivered = new Course[MAX_COURSES_COUNT];
	private int coursesCount = 0;
	
	/**
	 * Constructs a teacher with specific name and degree 
	 * @param name the teacher's name
	 * @param academicDegree the teachers degree
	 */
	public Teacher(Name name, AcademicDegree academicDegree) {
		this.name = name;
		this.academicDegree = academicDegree;
	}
	
	/** 
	 * makes Teacher to deliver lecture corresponding to the specified course
	 * @param course course to which the lecture belongs
	 * @return true if student successfully attended lecture
	 */
	@Override
	public boolean attendLecture(Course course) {
		// TODO: Replace degree check with method on enum
		if (teachesCourse(course)
				&& (academicDegree == AcademicDegree.PROFESSOR || academicDegree == AcademicDegree.DOCENT)) { 
			System.out.println("Teacher delivers a lecture");
			return true;
		} else {
			System.out.println("This teacher is inappropriate for the specified course");
			return false;
		}
	}

	/**
	 * Checks if this teacher can teach the course
	 * @param course 
	 * @return true if this teacher is to teach the course
	 */
	protected boolean teachesCourse(Course course) {
		if (Arrays.asList(coursesDelivered).contains(course)) {
			return true;
		} 
		return false;
	}
	
	/**
	 * Makes this teacher responsible for delivering the course
	 * @param course the course to deliver
	 * @return true if the course was added
	 */
	public boolean addCourse(Course course) {
		if ((coursesCount <= MAX_COURSES_COUNT) && (!teachesCourse(course))) {
			coursesDelivered[coursesCount] = course;
			coursesCount++;
			return true;
		}
		return false;
	}
	
	public enum AcademicDegree {
		PROFESSOR, DOCENT, ASSISTANT
	}
}
